/*
 * app_lamp.h
 *
 *  Created on: 2018年5月6日
 *      Author: 0yfj0
 */

#ifndef _APP_LAMP_H_
#define _APP_LAMP_H_
#ifdef __cplusplus
extern "C"
{
#endif  /* __cplusplus */
#include <stdint.h>

/*----------------------------------------------------------------------------*/
#define LAMP_SZ			( 1 )
#define LAMP_TBAKUP		( 600 )
#define LAMP_RANGE_SZ	( 8 )
#define LAMP_EDGE_SZ	( 16 )
typedef struct
{
	uint32_t vox :1;/* 全局声控使能 */
	uint32_t ir :1;/* 全局红外控制使能 */
	uint32_t delay_close :8;/* 延时关闭/分 */
} lamp_conf_ctrl_t;

typedef struct
{
	uint32_t enable :1;/* 启用此区间段 */
	uint32_t once :1;/* 0-循环，1-单次 */
	uint32_t vox :1;/* 区间声控使能 */
	uint32_t ir :1;/* 区间红外控制使能 */
	uint32_t start :12;/* 区间段起始12:00 1200 */
	uint32_t end :12;/* 区间段结束13:00 1300 */
} lamp_conf_range_t;

typedef struct
{
	uint16_t enable :1;/* 启用 */
	uint16_t once :1;/* 0-循环，1-单次 */
	uint16_t on :1;/* 0-edge off, 1-edge on */
	uint16_t edge :12;/* 12:00 1200 */
} lamp_conf_edge_t;

typedef struct
{
	lamp_conf_ctrl_t ctrl;
	lamp_conf_range_t range[LAMP_RANGE_SZ];
	lamp_conf_edge_t edge[LAMP_EDGE_SZ];
} lamp_conf_t;

typedef struct
{
	lamp_conf_t conf[LAMP_SZ];
	uint32_t range_start[LAMP_SZ][LAMP_RANGE_SZ];
	uint32_t range_end[LAMP_SZ][LAMP_RANGE_SZ];
	uint32_t edge[LAMP_SZ][LAMP_EDGE_SZ];
	struct
	{
		uint32_t run[LAMP_SZ];
		uint32_t lamp[LAMP_SZ];
	} stat;
	uint16_t tempx100;
	uint16_t humx100;
	uint8_t current_time[10];
	uint32_t tbakup;
} lamp_t;
extern lamp_t app;

/*----------------------------------------------------------------------------*/
void lamp_env_init(void);
int lamp_init(void);
int lamp_conf(void *buf, uint16_t len);
int lamp_startup(void);
int lamp_ctrl(int lamp, int state);
void lamp_event_reset(void);
void lamp_loop_task(void);
void lamp_timer1s_timeout_handler(void *p_context);

/*----------------------------------------------------------------------------*/

#ifdef __cplusplus
}
#endif  /* __cplusplus */
#endif /* _APP_LAMP_H_ */
